package com.mhs.services;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class ServiceMap {
	private static String WSDL_TARGET_NAMESPACE = PublicVariable
			.getWsdlTargetNamespace();

	private static String SOAP_ADDRESS = PublicVariable.getSoapAddress();

	public static SoapObject InvokeMethod(String urlAddress) {
		
		String SOAP_ACTION = "http://tempuri.org/responseXMLStringFromGPlace";
		String OPERATION_NAME = "responseXMLStringFromGPlace";
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);

		if (!urlAddress.isEmpty()) {
			PropertyInfo pi = new PropertyInfo();
			pi.setName("urlAddress");
			pi.setValue(urlAddress);
			pi.setType(String.class);
			request.addProperty(pi);
		}

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);

		HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_ADDRESS);
		SoapObject response = null;
		try {
			androidHttpTransport.call(SOAP_ACTION, envelope);
			KvmSerializable ks = (KvmSerializable)envelope.bodyIn;
			for(int i = 0;i < ks.getPropertyCount();i++){
				ks.getProperty(i);
			}
			response = (SoapObject) ks;
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return response;
	}
	
	public static SoapObject getFoneNumberFromGMap(String urlAddress) {
		
		String SOAP_ACTION = "http://tempuri.org/responseXMLStringFoneNumberFromGPlace";
		String OPERATION_NAME = "responseXMLStringFoneNumberFromGPlace";
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);

		if (!urlAddress.isEmpty()) {
			PropertyInfo pi = new PropertyInfo();
			pi.setName("urlAddress");
			pi.setValue(urlAddress);
			pi.setType(String.class);
			request.addProperty(pi);
		}

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);

		HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_ADDRESS);
		SoapObject response = null;
		try {
			androidHttpTransport.call(SOAP_ACTION, envelope);
			KvmSerializable ks = (KvmSerializable)envelope.bodyIn;
			for(int i = 0;i < ks.getPropertyCount();i++){
				ks.getProperty(i);
			}
			response = (SoapObject) ks;
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return response;
	}
}
